﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using Database.Classes;

public partial class UserDefinedFunctions
{
    public static List<int[]> GetAllSystemsFromBioRange(int sId, int bio)
    {
        List<int[]> tmp = new List<int[]>();
        List<int> cords = SystemCoordinates(sId);

        using (SqlConnection conn = new SqlConnection(StaticMethods.ConnectionString()))
        {
            conn.Open();
            using (SqlCommand cmd = new SqlCommand("Select x, y from Systems where @minX <= x and x <= @maxX and @minY <= y and y <= @maxY AND (SystemID <= (SELECT LastOrginID FROM Configuration))", conn))
            {
                cmd.Parameters.Add("@minX", SqlDbType.Float).Value = cords[0] - bio / 2;
                cmd.Parameters.Add("@maxX", SqlDbType.Float).Value = cords[0] + bio / 2;
                cmd.Parameters.Add("@minY", SqlDbType.Float).Value = cords[1] - bio / 2;
                cmd.Parameters.Add("@maxY", SqlDbType.Float).Value = cords[1] + bio / 2;

                SqlDataReader rdr = cmd.ExecuteReader();
                while (rdr.Read())
                {
                    int[] t = new int[2];
                    t[0] = rdr.GetInt32(0);
                    t[1] = rdr.GetInt32(1);
                    tmp.Add(t);
                }
            }
        }

        return tmp;
    }
};

